package com.gjy.util.sb.advice;

import com.gjy.util.sb.entity.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-10-24 08:42:25
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = Exception.class)
    public AjaxResult exceptionHandler(HttpServletRequest request, Exception e) {
        log.error("{}", request.getServletPath());

        log.error("异常信息: {}", e.getMessage());
        AjaxResult r = new AjaxResult();
        r.setData("出现异常");
        r.setMessage("OO");
        r.setCode(600);

        return r;
    }
}
